package com.yznote.cloudesk.common.pojo;

import com.yznote.cloudesk.common.constants.YConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/10/12 20:56
 * 统一返回结果
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable,Cloneable {
    private T data;
    private Integer code;
    private String msg;

    public static <T> Result<T> build(T data, Integer code, String msg) {
        Result<T> result = new Result<>(data, code, msg);
        return result;
    }



    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data, 200, YConstant.RETURNSUCCESS);
        return result;
    }

    public static <T> Result<T> fail(String msg) {
        Result<T> result = new Result<>(null, 500, msg);
        return result;
    }
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
